/*****************************************************************************
Module :     URLEncDec.H
Notices:     Initially Written 2002 by ChandraSekar Vuppalapati.
			 2007.3.1 Re-written by Ling, Xiao-li.  Mailto: ling.xiaoli.s@gmail.com
Description: 2007.7.22, Ling, Xiao-li.
			 Encode/Decode input ansi or mbcs string. 
			 You must call this class after convertting wide char string to multiple bytes string if input string
			 is wide char string as what API MultiByteToWideChar() does.

			 Keep in mind: 
			 string that needs to transport on Internet is different from on local system.
			 When URL Encoding applies, it only recognizes bytes, that is, when your local 
			 system adopts MBCS, the string not needs to change before URL Encoding, but if
			 your local system adopts UNICODE (wide char), then you should convert it to some
			 transportation charset (depends on Web Server side) before URL encoding, the most 
			 used UNICODE transportation charset is UTF-8 which takes one byte as encoding unit.
			 
			 At present, this class only support MBCS string and UTF-8/UTF-7 string just as IE's behavior.
			 FireFox also support:
			 UTF-16 (Big Endian and Little Endian), UTF-32 (Big Endian and Little Endian)

			 How CStringA treat the length of encoded char stream if MBCS defined? 
			 Call _mbslen() or _mbslen_l()????
			 
			 
*****************************************************************************/
#ifndef __CURLENCDEC_H_
#define __CURLENCDEC_H_

#include "stdafx.h"

// Does it need to support wide char string input?????

namespace System
{
	namespace Internet
	{

		class CURLEncDec
		{
		private:
			static CStringA csUnsafeString;	// URL encoding operating on bytes stream
			static CStringA DecToHex(const char num, int radix); // URL encoding operating on bytes stream
			static bool IsUnsafe(const char compareChar);
			static CStringA Convert(const char val); // URL encoding operating on bytes stream

			// helper to convert %XX to chars
			static char Hex2Ch (const char* pszHex);

			// can't construct a object
			CURLEncDec() { };
			virtual ~CURLEncDec() { };

		public:
			// Those need URL encoding string must either MBCS or UTF-8 char stream, and encoded result must be a ascii char stream
			static CStringA URLEncode(const char* lpszCharStream); 
			static CStringA URLDecode(const char* lpszCharStream);
		};

	};
};
#endif //__CURLENCODE_H_